package com.tc.zigbee.zcl.command;

import java.util.LinkedList;
import java.util.List;

import com.tc.util.DataUtil;

public class ReadAttributeResponse extends AbstractZclCommand{
	public List<AttributeRecord> getAttributes() {
		return attributes;
	}
	List<AttributeRecord> attributes = new LinkedList<AttributeRecord>();
	public ReadAttributeResponse(byte[] data){
		int i = 0;
		while(i < data.length){
			
			byte[] ai = new byte[2];
			ai[0] = data[i++];
			ai[1] = data[i++];
			short aii = DataUtil.shortValue(ai);
			byte status = data[i++];
			DataValue dv = null;
			if(status == 0)
			{
				byte dt = data[i++];
				DataType dtt =DataTypeManager.types.get(dt);
				byte[] value = new byte[dtt.length];
				for(int j = 0; j < dtt.length; j++){
					value[j] = data[i++];
				}
				dv = new DataValue(dt, value);
				
			}
			AttributeRecord ar = new AttributeRecord(aii, status, dv);
			attributes.add(ar);
		}
		
	}
}
